package com.wyl.wyl.testapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wyl.wyl.testapplication.R;
import com.wyl.wyl.testapplication.bean.PersonMainBean;

import java.util.List;

import jp.wasabeef.glide.transformations.CropCircleTransformation;

/**
 * Created by es on 2019/4/24.
 */

public class PersonAdapter extends BaseAdapter {
    private Context context;
    private List<PersonMainBean.BodyBean.PersonBean> list;

    public PersonAdapter(Context context, List<PersonMainBean.BodyBean.PersonBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        PersonMainBean.BodyBean.PersonBean materialBean = list.get(position); // 获取当前项的CarBean实例
        Glide.with(context).load(materialBean.getFile_path()).bitmapTransform(
                new CropCircleTransformation(context)).into(holder.wol);
        holder.textView4.setText(materialBean.getName());
        holder.phoneNumber.setText(materialBean.getTelephone());
        holder.textView5.setText(materialBean.getPerson_type());

        return convertView;
    }

    private class ViewHolder {
        private ImageView wol;
        private TextView textView4;
        private TextView phoneNumber;
        private TextView textView5;

        public ViewHolder(View view) {
            wol = (ImageView) view.findViewById(R.id.wol);//获取该布局内的文本视图
            textView4 = (TextView) view.findViewById(R.id.textView4);
            phoneNumber = (TextView) view.findViewById(R.id.phoneNumber);
            textView5 = (TextView) view.findViewById(R.id.textView5);
        }
    }

}
